package com.example.server.service.impl;

import com.example.server.service.JdbcService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
@Slf4j
@Service
public class JdbcServiceImpl implements JdbcService {
    public Connection getConnection()
    {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        String url = "jdbc:mysql://180.76.112.114:3306/SXbankProduction?serverTimezone=GMT%2B8";
        String username = "sean";
        String password="123456";
        Connection a=null;
        try {
            a = DriverManager.getConnection(url,username,password);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return a;
    }
    public void createtable(String p_id)
    {
        Connection conn = getConnection();
        String sql = "create table p" + p_id + "(user_id varchar(50) primary key," +
                "buy_date datetime," +
                "deposit int not null comment '存款金额')";
        try {
            Statement cs = conn.createStatement();
            cs.executeUpdate(sql);
            cs.close();
            conn.close();

        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
    }
}
